<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2024/12/23 0023
  Time: 19:43
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="UTF-8">
    <title>物料组成设计单审核</title>
    <link rel="stylesheet"  href="/bootstrap/bootstrap-5.3.3-dist/css/bootstrap.min.css" />
    <link rel="stylesheet" href="/css/ProductDesign/module(1).css" />
</head>
<body style="padding: 15px 50px;background-color: #eeeeee;">
<div class="panel-heading hhead">
    <nav aria-label="breadcrumb">
        <ol class="breadcrumb">
            <span style="color: blue;">您正在做的业务是：</span>
            <li class="breadcrumb-item"><a href="#">产品设计</a></li>
            <li class="breadcrumb-item"><a href="#">产品物料组成设计</a></li>
            <li class="breadcrumb-item active" aria-current="page">物料组成设计单审核</li>
        </ol>
    </nav>
</div>

<form id="FM1">
    <div style="margin-bottom: 2px">
        <div style="display: inline;margin-left: 78%;">
            <input type="radio" name="checkTag" value="2" />未通过
            <input type="radio" name="checkTag" value="1" checked/>通过
            <input type="hidden" id="HiddenChecker" name="checker" value="">
            <input type="hidden" id="userName" value="${user.loginId}">
            <input type="hidden" id="id" name="id" value="">
            <button class="btn btn-primary" id="ok" type="button">确认</button>
<%--            <button class="btn btn-primary">返回</button>--%>
        </div>
    </div>
</form><!-- 此div改用栅格来做 -->
<div id="designListBox">
    <div style="text-align: center">
        <h3>物料组成设计单</h3>
    </div>
    <div style="padding: 30px">
        <form>
            <table class="tbl1">
                <tr>
                    <td class="col1">设计单编号：</td>
                    <td class="col2" id="designId">aaa</td>
                    <td class="col1">设计人：</td>
                    <td class="col2"><input type="text" class="txt_under_line" id="designer"></td>
                </tr>
                <tr>
                    <td class="col1">产品名称：</td>
                    <td colspan="1" id="productName"></td>
                    <td class="col1">产品编号：</td>
                    <td colspan="2" id="productId"></td>
                </tr>
            </table>

            <table class="table table-bordered" style="margin: 15px auto;">
                <thead>
                <tr>
                    <th>序号</th><th>物料名称</th><th>物料编号</th>
                    <th>用途类型</th><th>描述</th><th>数量</th>
                    <th>单位</th><th>单价（元）</th><th>小计（元）</th>
                </tr>
                </thead>
                <tbody id="template">
                <tr>
                    <td ></td>
                    <td>aaaaaaaaaaaaaaaaaaaa</td>
                    <td>aaaaaaaaaaaaa</td>
                    <td>a</td>
                    <td>a</td>
                    <td class="num">
                        <input class="num-input"></td>
                    <td>a</td>
                    <td>a</td>
                    <td>a</td>
                </tr>
                </tbody>
            </table>

            <table class="tbl3">
                <tr>
                    <td class="col1">物料总成本：</td>
                    <td class="col2"><input id="costPriceSum" type="text" class="txt_under_line"></td>
                </tr>
                <tr>
                    <td class="col1">审核人：</td>
                    <td class="col2"><input id="checker" type="text" class="txt_under_line"></td>
                    <td class="col1">审核时间：</td> <td class="col2" id="checkTime">系统时间</td>
                </tr>
                <tr>
                    <td class="col1">设计要求：</td>
                    <td colspan="3" style="padding-top: 5px">
                        <textarea id="moduleDescribe" rows="4" cols="100"></textarea>
                    </td>
                </tr>
            </table>
        </form>
    </div>
</div>
<script type="text/javascript" src="/js/jquery-3.7.0.min.js"></script>
<script type="text/javascript" src="/bootstrap/bootstrap-5.3.3-dist/js/bootstrap.bundle.min.js"></script>
<script type="text/javascript" src="/js/common.js"></script>
<script type="text/javascript">
    $(function (){
        // 初始化数据
        ItemApprovalTable();

        // 初始化时间
        setInterval(updateDateTime, 1000);

        $("#ok").click(function (){
            let b = confirm("确认审核吗？(以最后一次确认的结果为准)",Audit,"确认","取消");
            if (b){
                Audit();
            }
        })

    })
    function ItemApprovalTable(){
        let id = sessionStorage.getItem("id");
        $("#id").val(id);
        $.ajax({
            url: "/d-module-details/ItemApprovalTable?id="+id,
            type: "GET",
            dataType: "json",
            success: function (data) {
                console.log(data);
                if (data.errCode == "1") {
                    alert(data.errMsg)
                } else {
                    $("#designId").text(data.designId);
                    $("#designer").val(data.designer);
                    $("#productName").text(data.productName);
                    $("#productId").text(data.productId);
                    $("#costPriceSum").val(data.costPriceSum);
                    $("#checker").val(data.checker);
                    $("#checkTime").text(data.checkTime);
                    $("#moduleDescribe").val(data.moduleDescribe);
                    initialTemplate(data.id);
                }
            }
        })
    }
    function initialTemplate(parentId){
        $.ajax({
            url: "/d-module-details/initialTemplate?id="+parentId,
            type: "GET",
            dataType: "json",
            success: function (data) {
                console.log(data);
                if (data.errCode == "1") {
                    alert(data.errMsg)
                } else {
                    let template = $("#template");
                    // 清空表格
                    template.empty();
                    // 遍历数据并添加到表格中
                    data.forEach(function (item, index) {
                        let row = $("<tr>");
                        row.append($("<td>").text(index + 1));
                        row.append($("<td>").text(item.productName));
                        row.append($("<td>").text(item.productId));
                        row.append($("<td>").text(item.dproductUse["useName"]));
                        row.append($("<td>").text(item.productDescribe));
                        row.append($("<td>").text(item.amount));
                        row.append($("<td>").text(item.amountUnit));
                        row.append($("<td>").text(item.costPrice));
                        row.append($("<td>").text(item.subtotal));
                        template.append(row);
                    })

                }
            }
        })
    }
    function Audit() {
        let checker = $("#checker").val()
        if (checker == ""){
            $("#HiddenChecker").val($("#userName").val())
            $("#checker").val($("#userName").val())
        } else {
            $("#HiddenChecker").val(checker)
        }
        let json = formDateToJson("FM1");
        sessionStorage.clear();
        sessionStorage.setItem("json",json);
    }
    function updateDateTime(){
        let date = new Date();
        let year = date.getFullYear();
        let month = (date.getMonth() + 1).toString().padStart(2, '0');
        let day = date.getDate().toString().padStart(2,'0');
        let hours = date.getHours().toString().padStart(2,'0');
        let minutes = date.getMinutes().toString().padStart(2,'0');
        let seconds = date.getSeconds().toString().padStart(2,'0');
        let dateTimeStr = year+"-"+month+"-"+day+" "+hours+":"+minutes+":"+seconds;
        $("#checkTime").text(dateTimeStr);
    }
</script>
</body>
</html>
